package ru.st.selenium.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class NewFilmPage extends AnyPage {
	
	public NewFilmPage(PageManager pages) {
		super(pages);
	}

  @FindBy(name = "imdbid")
	  private WebElement IMDbField;

  @FindBy(name = "name")
      private WebElement titleField;

  @FindBy(name = "year")
      private WebElement yearField;

  @FindBy(name = "submit")
      private WebElement submitButton;
  
  @FindBy(css = "img[alt=\"Add movie\"]")
      private WebElement AddFilmButton;
  
  @FindBy(css = "label.error")
public static WebElement LabelError;
  
  public NewFilmPage setIMDbField(String text) {
	  IMDbField.sendKeys(text);
	    return this;
	  }
  
  public NewFilmPage setTitleField(String text) {
	  titleField.sendKeys(text);
	    return this;
	  }  

  public NewFilmPage setYearField(String text) {
	  yearField.sendKeys(text);
        return this;
  }
  
  public NewFilmPage checkLabelError() {
	  LabelError.getText();
        return this;
  }
  public void clickSubmitButton() {
    submitButton.click();
  }
  
  public void clickAddFilmButton() {
	  AddFilmButton.click();
	  }
  
  public NewFilmPage ensurePageLoaded() {
	    super.ensurePageLoaded();
	    wait.until(presenceOfElementLocated(By.name("year")));
	    return this;
	  }
}
